/**
 * CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

package com.cmcc.zysoft.infocollection.controller;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cmcc.zysoft.infocollection.common.BaseController;
import com.cmcc.zysoft.infocollection.service.MenuPcService;
import com.cmcc.zysoft.infocollection.service.RoleMenuPcService;
import com.cmcc.zysoft.infocollection.service.RolePcService;

/**
 * @author 袁凤建
 * <br />邮箱: yuan.fengjian@ustcinfo.com
 * <br />描述: RoleMenuController.java
 * <br />版本: 1.0.0
 * <br />日期: 2013-9-6 上午9:39:04
 * <br />CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

@Controller
@RequestMapping("/pc/roleMenu")
public class RoleMenuController extends BaseController {

	/**
	 * 属性名称: rolePcService.
	 * 类       型: RolePcService.
	 */
	@Resource
	private RolePcService rolePcService;
	
	/**
	 * 属性名称: menuPcService.
	 * 类       型: MenuPcService.
	 */
	@Resource
	private MenuPcService menuPcService;
	
	/**
	 * 属性名称: roleMenuPcService.
	 * 类       型: RoleMenuPcService.
	 */
	@Resource
	private RoleMenuPcService roleMenuPcService;
	
	/**
	 * 权限管理页面.
	 * @return String
	 */
	@RequestMapping("/main.htm")
	public String main() {
		return "/pc/roleMenu/list";
	}
	
	/**
	 * 获取角色分页列表信息.
	 * @param page 页码
	 * @param rows 每页记录数
	 * @return Map<String, Object>
	 */
	@RequestMapping("/roles.htm")
	@ResponseBody
	public Map<String, Object> roles(int page, int rows) {
		return this.rolePcService.roles(page, rows);
	}
	
	/**
	 * 获取菜单树.
	 * @return List<Map<String, Object>>
	 */
	@RequestMapping("/tree.htm")
	@ResponseBody
	public List<Map<String, Object>> menuTree() {
		return this.menuPcService.menuTree();
	}
	
	/**
	 * 通过角色ID获取角色对应的菜单.
	 * @param roleId 角色ID
	 * @return List<Map<String, Object>>
	 */
	@RequestMapping("/getMenuByRoleId.htm")
	@ResponseBody
	public List<Map<String, Object>> getMenuByRoleId(String roleId) {
		return this.roleMenuPcService.getMenuByRoleId(roleId);
	}
	
	/**
	 * 增加叶子节点菜单.
	 * @param roleId 角色ID
	 * @param menuId 菜单ID
	 * @return String
	 */
	@RequestMapping("/add.htm")
	@ResponseBody
	@Transactional
	public String add(String roleId, String menuId) {
		String result = this.roleMenuPcService.add(roleId, menuId);
		if(StringUtils.hasText(result)) {
			return "SUCCESS";
		} else {
			return "FAILURE";
		}
	}
	
	/**
	 * 删除叶子节点菜单.
	 * @param roleId 角色ID
	 * @param menuId 菜单ID
	 * @return String
	 */
	@RequestMapping("/delete.htm")
	@ResponseBody
	@Transactional
	public String delete(String roleId, String menuId) {
		this.roleMenuPcService.delete(roleId, menuId);
		return "SUCCESS";
	}
	
	/**
	 * 增加非叶子节点菜单.
	 * @param roleId 角色ID
	 * @param menuId 菜单ID
	 * @return String
	 */
	@RequestMapping("/addAll.htm")
	@ResponseBody
	@Transactional
	public String addAll(String roleId, String menuId) {
		this.roleMenuPcService.addAll(roleId, menuId);
		return "SUCCESS";
	}
	
	/**
	 * 增加非叶子节点菜单.
	 * @param roleId 角色ID
	 * @param menuId 菜单ID
	 * @return String
	 */
	@RequestMapping("/deleteAll.htm")
	@ResponseBody
	@Transactional
	public String deleteAll(String roleId, String menuId) {
		this.roleMenuPcService.deleteAll(roleId, menuId);
		return "SUCCESS";
	}
}